﻿//
// eCRAM, a monthly activity report web application
// Copyright (C) 2010  Aptea
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//

using System.Configuration;
using System.Data.Linq;
using System.Linq;
using System.Collections.Generic;
using Microsoft.Practices.Unity;

namespace eCRAM.Dao
{
    /// <summary>
    /// Pattern repository for LINQ to SQL.
    /// </summary>
    /// <remarks>
    /// Factorize code for repositories using LINQ to SQL.
    /// </remarks>
    public abstract class LinqRepository<T> : IRepository<T>
    {

        public LinqRepository(DataContext dataContent)
        {
            DataContext = dataContent;
        }

        /// <summary>
        /// Data context: link to the SQL database.
        /// </summary>
        public DataContext DataContext { get; set; } //= new DataContext(ConfigurationManager.ConnectionStrings["eCRAM"].ConnectionString);

        public abstract IQueryable<T> GetAll();

        public abstract void Create(T t);
        
       // public abstract void Update(T t);
        
        public abstract void Delete(T t);

        public abstract T GetById(System.Guid id);

        public abstract IQueryable<T> GetTop(int start, int limit);

        public abstract int GetCount();

        public void SubmitChanges()
        {
            DataContext.SubmitChanges();
        }
    }
}
